package com.ling.design;

import com.ling.design.impl.MJCouponDiscount;
import com.ling.design.impl.NYGCouponDiscount;
import com.ling.design.impl.ZJCouponDiscount;
import com.ling.design.impl.ZKCouponDiscount;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: ling007
 * @date: 2024/9/29 17:29
 * @description:
 */

public class ApiTest {

    private Logger logger = LoggerFactory.getLogger(ApiTest.class);

    @Test
    public void test_zj() {
        // 直减；100-10，商品100元
        Context<Double> context = new Context<Double>(new ZJCouponDiscount());
        BigDecimal discountAmount = context.discountAmount(10D, new
                BigDecimal(100));
        logger.info("测试结果：直减优惠后⾦金金额 {}", discountAmount);
    }

    @Test
    public void test_mj() {
        // 满减；满100-10，商品100元
        Context<Map<String, String>> mapContext = new Context<>(new MJCouponDiscount());
        HashMap<String, String> map = new HashMap<>();
        map.put("x", "100");
        map.put("n", "20");
        BigDecimal discountAmount = mapContext.discountAmount(map, new BigDecimal(200));
        logger.info("测试结果：满减优惠后⾦金金额 {}", discountAmount);
    }
    @Test
    public void test_ny(){
        Context<Double> context = new Context<Double>(new NYGCouponDiscount());
        BigDecimal discountAmount = context.discountAmount(10D, new BigDecimal(100));
        logger.info("测试结果：nyg优惠后⾦金金额 {}", discountAmount);
    }

    @Test
    public void test_zk(){
        Context<Double> context = new Context<Double>(new ZKCouponDiscount());
        BigDecimal discountAmount = context.discountAmount(0.9D, new BigDecimal(100));
        logger.info("测试结果：zk优惠后⾦金金额 {}", discountAmount);
    }
}
